-- 把table转为字符串
function table_to_str(obj)
    local lua = ""
    local t = type(obj)
    if t == "number" then
        lua = lua .. obj
    elseif t == "boolean" then
        lua = lua .. tostring(obj)
    elseif t == "string" then
        lua = lua .. string.format("%q", obj)
    elseif t == "table" then
        lua = lua .. "{"
        for k, v in pairs(obj) do
            lua = lua .. "[" .. table_to_str(k) .. "]=" .. table_to_str(v) .. ","
        end
        local metatable = getmetatable(obj)
        if metatable ~= nil and type(metatable.__index) == "table" then
            for k, v in pairs(metatable.__index) do
                lua = lua .. "[" .. table_to_str(k) .. "]=" .. table_to_str(v) .. ","
            end
        end
        lua = lua .. "}"
    elseif t == "nil" then
        return nil
    elseif t == "function" then
        return nil
    else
        return obj:__tostring()
        -- error("can not serialize a " .. t .. " type.")  
    end
    return lua
end

-- 把字符串转为table
function str_to_table(table_str)
    if table_str == nil or type(table_str) ~= "string" then
        return
    end
    return load("return " .. table_str)()
end

function split(input, delimiter)
    input = tostring(input)
    delimiter = tostring(delimiter)
    if (delimiter == "") then
        return {}
    end
    local pos, arr = 0, {}
    for st, sp in function()
        return string.find(input, delimiter, pos, true)
    end do
        table.insert(arr, string.sub(input, pos, st - 1))
        pos = sp + 1
    end
    table.insert(arr, string.sub(input, pos))
    return arr
end
